import Vue from 'vue'
import Vuex from 'vuex'
import {fuzhouCdata, fuzhouGeoCoordMap, fuzhouSeriesData, getMapData} from "../utils/getMapData";

Vue.use(Vuex)

const loginModule = {
  state: {
    currentUser: {},
  },
  mutations: {
    updateCurrentUser(state,userInfo){
      state.currentUser = userInfo
    }
  }
}

const clickedAreaModule = {
  state: {
    clickedArea: {
      data: {
        name: '福州市',
        cdata: fuzhouCdata,
        geoCoordMap: fuzhouGeoCoordMap,
        seriesData: fuzhouSeriesData
      }
    },
  },
  mutations: {
    updateClickedArea(state,newClickedArea){
      console.log("newClickArea=>",newClickedArea)
      state.clickedArea.data = getMapData(newClickedArea.data.name)
    }
  }
}

const websocketModule = {
  state: {
    ws: null,
  },
  mutations: {
    updateWs(state,ws){
      state.ws = ws;
    },
    closeWs(state){
      state.ws.disconnect()
    },
  }
}

const store = new Vuex.Store({
    modules: {
      loginModule: loginModule,
      clickedAreaModule: clickedAreaModule,
      websocketModule: websocketModule
    }
})

export default store
// export default new Vuex.Store({
//   state: {
//   },
//   mutations: {
//   },
//   actions: {
//   },
//   modules: {
//   }
// })
